package com.yuan.Controller.admin;


import com.yuan.Service.OrderService;
import com.yuan.dto.OrdersCancelDTO;
import com.yuan.dto.OrdersConfirmDTO;
import com.yuan.dto.OrdersPageQueryDTO;
import com.yuan.dto.OrdersRejectionDTO;
import com.yuan.result.PageResult;
import com.yuan.result.Result;
import com.yuan.vo.OrderStatisticsVO;
import com.yuan.vo.OrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("admin/order")
@Slf4j
@Tag(name = "订单管理接口")
public class OrderController {

    private final OrderService orderService;

    //订单搜索
    @GetMapping("/conditionSearch")
    @Operation(description = "订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索:{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);

    }

    // 各个状态的订单数量统计
    @GetMapping("/statistics")
    @Operation(description = "各个状态的订单数量统计\"")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);

    }

    //订单详情
    @GetMapping("/details/{id}")
    @Operation(description = "查询订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO orderVO = orderService.details(id);
        return Result.success(orderVO);
    }


    //接单
    @PutMapping("/confirm")
    @Operation(description = "接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    //拒单
    @PutMapping("/rejection")
    @Operation(description = "拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {

        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    //取消订单
    @PutMapping("/cancel")
    @Operation(description = "取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    //派送订单
    @PutMapping("/delivery/{id}")
    @Operation(description = "派送订单")
    public Result delivery(@PathVariable Long id) {
        orderService.delivery(id);
        return Result.success();
    }


    // 完成订单
    @PutMapping("/complete/{id}")
    @Operation(description = " 完成订单")
    public Result complete(@PathVariable Long id) {
        orderService.complete(id);
        return Result.success();

    }


}
